import React,{useState,useEffect} from 'react'
import { Table, Space, Button } from 'antd';
import {Link} from 'react-router-dom'
import { jobCfyList } from '../../api/job'
const columns = [
  {
    title: '分类ID',
    dataIndex: 'objectId',
    key: 'objectId',
    render: text => <a>{text}</a>,
  },
  {
    title: '分类名称',
    dataIndex: 'cfyname',
    key: 'cfyname',
  },
  {
    title: '归属分类',
    dataIndex: 'cfytype',
    key: 'cfytype',
  },
  {
    title: '分类图标',
    key: 'cfyimg',
    dataIndex: 'cfyimg',
    render:(url)=>{
      return <img  src={url} style={{height:'50px'}}/>
    }
  },
  {
    title: '操作',
    key: 'action',
    render: (obj) => {
      // console.log(obj); //此处的obj是用以渲染某一行的数据包
      return (
          <Space size="middle">
            <Link to={`/admin/cfy/edit/${obj.objectId}`}>
              <Button type="primary" size="small">编辑</Button>
            </Link>
            <Button type="danger" size="small">删除</Button>
          </Space>
      )
    },
  },
];

const initdata = [
  {
    key: '1',
    objectId: 'John Brown',
    cfyname: '公司老总',
    cfytype: 1,
    cfyimg: 'img.png',
  }
];

const CfyList = ()=>{
  let [data,setData] = useState(initdata)
  useEffect(()=>{
    jobCfyList().then(res=>{
      console.log(res);
      setData(res.data.results)
    })
  },[])
  return <Table columns={columns} dataSource={data} />
}

export default CfyList

